﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

/*For observable collection */
using System.Collections.ObjectModel;

namespace WPF_DataLogger
{
    /// <summary>
    /// Interaction logic for Window2.xaml
    /// </summary>
    public partial class SettingWindow : Window
    {
        public SettingWindow(List<string> name_list)
        {
            InitializeComponent();
            UserComponentsInit(name_list);
        }

        private void UserComponentsInit(List<string> name_list)
        {
            gas_name_list = name_list;
            GasListBox.Loaded += new RoutedEventHandler(LoadList);
        }

        private void LoadList(object sender, RoutedEventArgs e)
        {         
            this.GasNameList = new ObservableCollection<string>();

            foreach(string name in gas_name_list)
            {
                this.GasNameList.Add(name);
            }
        }

        private void AddGasItem_Click(object sender, RoutedEventArgs e)
        {
            gas_name_list.Add(textBox1.Text);
            this.GasNameList.Add(textBox1.Text);
        }

        private void DeleteGas_Click(object sender, RoutedEventArgs e)
        {
            int idx = GasListBox.Items.IndexOf(GasListBox.SelectedItem);
            gas_name_list.RemoveAt(idx);
            this.GasNameList.RemoveAt(idx);
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        //Properties
        public ObservableCollection<string> GasNameList
        {
            get 
            { 
                return (ObservableCollection<string>)GetValue(GasListBoxProperty); 
            }
            set 
            {
                SetValue(GasListBoxProperty, value); 
            }

        }

        public static readonly DependencyProperty GasListBoxProperty =
                DependencyProperty.Register("GasNameList", typeof(ObservableCollection<string>), 
                typeof(SettingWindow), new UIPropertyMetadata(null));


        //Data Section
        List<string> gas_name_list;
    }
}
